package edu.seu.mart.dao.impl;

import edu.seu.mart.dao.ISellerDao;
import edu.seu.mart.dao.BaseDao;
import edu.seu.mart.entity.Pager;
import edu.seu.mart.entity.SystemRequest;
import edu.seu.mart.entity.SystemRequestHolder;
import edu.seu.mart.model.Seller;
import org.springframework.stereotype.Repository;

@Repository("sellerDao")
public class SellerDao extends BaseDao<Seller> implements ISellerDao {

    @Override
    public Seller loadByUsername(String username) {
        String hql = "from Seller where name = ?";
        return (Seller) this.queryObject(hql, username);
    }

    @Override
    public Pager<Seller> findUser(String order) {
        if (order == null) {
            order="desc";
        }
        SystemRequest systemRequest = new SystemRequest();
        systemRequest.setOrder(order);
        systemRequest.setSort("credibility");
        SystemRequestHolder.initRequestHolder(systemRequest);
        return this.find("from Seller");
    }

    @Override
    public Pager<Seller> findSeller(String name) {
        return this.find("from Seller where name='"+name+"'");
    }
}
